#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <map>
using namespace std;

void test01()
{
    string str="hello world";
    string words="aeiou";
    int index=str.find_first_of(words);
    cout<<index<<endl;
    str[index]='*';
    cout<<str<<endl;

    while(index!=string::npos){
        str[index]='*';
        index=str.find_first_of(words,index+1);
    }
    cout<<str<<endl;
}

void test02(){
    string str="hello world";
    string words="aeiou";
    int index=str.find_last_of("aeiou");
    str[index]='*';
    cout<<str<<endl;

    vector<string> paths={
            "cpp0616\\cpp0825.cpp",
            "D:/cpp_study/project/cpp0616/cpp0826.cpp"
    };
    for(auto& path:paths){
        int index=path.find_last_of("/\\");
        cout<<index<<endl;
        string str=path.substr(index+1);
        cout<<str<<endl;
    }
}

string strip(const string& str){
    int start=str.find_first_not_of(" \n\t");
    int end=str.find_last_not_of(" \n\t");
    if(start==string::npos||end==string::npos)
    {
        return str;
    }
    return str.substr(start,end-start+1);
}

void test03(){
    FILE *p=fopen("C:\\Users\\30938\\Desktop\\old.txt","r");
    FILE* dest=fopen("C:\\Users\\30938\\Desktop\\new .txt","w");

    while(!feof(p)){
        char buffer[256]={0};
        fgets(buffer,sizeof(buffer),p);
        string line=strip(buffer)+'\n';
        fputs(line.data(),dest);
    }
    fclose(p);
    fclose(dest);
}

void test04()
{
    map<char,int> first;
    first['a']=10;
    first['b']=30;
    first['c']=50;
    first['d']=70;
    map<char,int> second(first.begin(),first.end());
    cout<<second.size()<<endl;

    map<int,char> _map={{1,'a'},
                        {2,'b'},
                        {3,'d'}};
    map<int,char>_map2;
    _map2.insert({4,'d'});
    _map2.insert(make_pair(5,'e'));
    _map2[6]='f';
    _map2[7]='g';
    for(const pair<char,int>&elem:second){
        cout<<elem.first<<" = "<<elem.second<<endl;
    }
    map<char,int>::iterator it;
    for(auto it=second.begin();it!=second.end();++it)
    {
        cout<<(*it).first<<" = "<<it->second<<endl;
    }
}

void test05(){
    string str="hello world";
    string words="aeiou";
    int index=str.find_last_of("aeiou");
    cout<<index<<endl;
    str[index]='*';
    cout<<str<<endl;
}

int main(){
    //test05();
   // test04();
  // test03();
    test02();
   // test01();
    return 0;
}

